package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"
	"go-zero-mall/app/admin/model"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type RoleUpdateStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRoleUpdateStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleUpdateStatusLogic {
	return &RoleUpdateStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 角色-更新状态
func (l *RoleUpdateStatusLogic) RoleUpdateStatus(in *pd.UmsRoleUpdateStatusReq) (*pd.Response, error) {
	d, err := l.svcCtx.UmsRoleModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}
	var role model.UmsRole
	copier.Copy(&role, d)
	role.Status = in.Status
	err = l.svcCtx.UmsRoleModel.Update(l.ctx, &role)
	if err != nil {
		return nil, err
	}
	return &pd.Response{Result: 1}, nil
}
